package com.example.front.controller;

import com.example.common.dto.JsonResult;
import com.example.common.dto.ListDto;
import com.example.common.dto.Pagination;
import com.example.common.exception.BusinessException;
import com.example.front.dto.BoxCreateDto;
import com.example.front.entity.Department;
import com.example.front.entity.Equipment;
import com.example.front.serivce.DepartmentService;
import com.example.interceptor.UserContext;
import com.example.passport.dto.WxUserDto;
import com.example.passport.entity.User;
import com.example.passport.mapper.UserMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@Api(tags = "部门管理")
@RestController
@CrossOrigin
@RequestMapping("/front/department")
public class DepartmentController {

    @Resource
    DepartmentService departmentService;



    @GetMapping("/list")
    @ApiOperation("获取用户信息")
    public JsonResult<ListDto<Department>> list(@Valid Department condition, Pagination pagination) {
        condition.setTenantId(UserContext.getUser().getTenantId());
        return new JsonResult<>(departmentService.list(condition, pagination));
    }

    @ApiOperation("添加盒子类型")
    @PostMapping("/create")
    public JsonResult<String> create(@Valid Department condition) {
        User me = UserContext.getUser();
        condition.setTenantId(me.getTenantId());
        departmentService.create(condition);
        return new JsonResult<>();
    }

    @ApiOperation("修改数据")
    @PostMapping("/update")
    public JsonResult<String> update(@Valid Department condition) {
        User me = UserContext.getUser();
        condition.setTenantId(me.getTenantId());
        departmentService.update(condition);
        return new JsonResult<>();
    }

    @ApiOperation("删除数据")
    @PostMapping("/delete")
    public JsonResult<String> delete(long id) {
        departmentService.deleteById(id);
        return new JsonResult<>();
    }

}
